package cc.orange.mainView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

import cc.orange.R;
import cc.orange.adapter.MessageFragmentAdapter;
import cc.orange.databinding.FragmentChatFriendBinding;
//import com.tendcloud.tenddata.TalkingDataSDK;

public class ChatFriendFragment extends Fragment {
    private FragmentChatFriendBinding binding;

    private List<Fragment> fragments=new ArrayList<>();

    private MessageFragmentAdapter messageFragmentAdapter;

    private String[] titles = {"好友", "关注", "粉丝"};

    ChatFriendItemFragment cartFriendFragment;
    ChatFriendItem1Fragment followFragment;
    ChatFriendItem2Fragment fansFragment;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_chat_friend, container, false);
        initViewPager();
        return binding.getRoot();
    }

    private void initViewPager() {
        cartFriendFragment = new ChatFriendItemFragment();
        followFragment = new ChatFriendItem1Fragment();
        fansFragment = new ChatFriendItem2Fragment();
        fragments.add(cartFriendFragment);
        fragments.add(followFragment);
        fragments.add(fansFragment);
        messageFragmentAdapter = new MessageFragmentAdapter(getActivity(), fragments);
        binding.vpChat.setAdapter(messageFragmentAdapter);
        TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(binding.tabChat, binding.vpChat, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(titles[position]);
            }
        });
        tabLayoutMediator.attach();
    }


    @Override
    public void onResume() {
        super.onResume();
//        TalkingDataSDK.onPageBegin(getActivity().getApplicationContext(), this.toString());
    }

    @Override
    public void onPause() {
        if(!this.isHidden()){
//            TalkingDataSDK.onPageEnd(getActivity().getApplicationContext(), this.toString());
        }
        super.onPause();
    }
}
